<template>
  <div class="panel-group">
    <div class="sigma-content">
      <div class="sigma-title">今日API产品情况</div>
      <div class="institution-content">
        <div
          class="institution"
          style="background-color: #FFF3E2;color: #FDA41F;"
        >
          <div class="name">
            在线API产品
          </div>
          <div class="num">{{ list.apiOnlineNum }}</div>
        </div>

        <div
          class="institution"
          style="background-color: #E5ECFF;color: #376DF7;"
        >
          <div class="name">
            推送量
          </div>
          <div class="num">{{ list.collisionNum }}</div>
        </div>
        <div
          class="institution"
          style="background-color: #E9F8F3;color: #35CD99;"
        >
          <div class="name">
            成功量
          </div>
          <div class="num">{{ list.applyNum }}</div>
        </div>
        <div
          class="institution"
          style="background-color: #FFEAEA;color: #ED5B5B;"
        >
          <div class="name">
            推送成功率
          </div>
          <div class="num">{{ list.applySuccessPercent }}</div>
        </div>
      </div>
    </div>
    <div class="sigma-content">
      <div class="sigma-title">API产品排行</div>
      <div class="apilist-content">
        <div class="api-title">
          <span style="width: 15%;">排行</span>
          <span style="width: 25%;">产品名称</span>
          <span style="width: 20%;">推送量</span>
          <span style="width: 20%;">成功量</span>
          <span style="width: 20%;">成功率</span>
        </div>
        <div class="apilist-box">
          <div
            class="apilist"
            v-for="(item, index) in tableData"
            :key="item"
            :class="index % 2 == 1 ? 'apiColor' : ''"
          >
            <span style="width: 15%;" v-if="item.sort < 4"
              ><span
                style="background-color: #FF4D4F;border-radius: 50%; padding: 4px 8px ;color: #FFFFFF;"
                >{{ item.sort }}</span
              ></span
            >
            <span style="width: 15%;" v-if="item.sort > 3">{{
              item.sort
            }}</span>
            <span style="width: 25%;">{{ item.apiName }}</span>
            <span style="width: 20%;">{{ item.collisionNum }}</span>
            <span style="width: 20%;">{{ item.applyNum }}</span>
            <span
              style="width: 20%;"
              :class="item.applySuccessPercent < 75 ? 'lowColor' : ''"
              >{{ item.applySuccessPercent }}%</span
            >
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { apiSituation, apiTop } from '@/api/home';
import { timestampToTime } from '@/utils/index';
require('echarts/theme/macarons'); // echarts theme
import resize from '../components/mixins/resize';

export default {
  mixins: [resize],
  data() {
    return {
      times: [],
      timeNow: [
        new Date(new Date().toLocaleDateString()).getTime(),
        new Date(new Date().toLocaleDateString()).getTime() +
          (24 * 60 * 60 * 1000 - 1)
      ],
      listQuery: {
        startTime: '',
        endTime: ''
      },
      list: {},
      tableData: []
    };
  },
  mounted() {
    this.listQuery.startTime = timestampToTime(this.timeNow[0]);
    this.listQuery.endTime = timestampToTime(this.timeNow[1]);
    this.getApiSituation();
    this.getApiTop();
  },
  methods: {
    async getApiSituation() {
      const res = await apiSituation(this.listQuery);
      if (res.data.code === 200) {
        this.list = res.data.data;
      }
    },
    async getApiTop() {
      const res = await apiTop(this.listQuery);
      if (res.data.code === 200) {
        this.tableData = res.data.data;
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.panel-group {
  width: 100%;
  // height: 386px;
  border-radius: 2px;
  padding: 16px;
  margin-top: 16px;
  background-color: #ffffff;
  .sigma-content {
    .sigma-title {
      width: 200px;
      font-size: 16px;
      border-left: 3px solid #376df7;
      padding: 0 4px;
      line-height: 11px;
      margin: 2px 0;
    }
    .institution-content {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      align-items: center;
      padding: 12px 0 10px 0;
      .institution {
        width: 48%;
        padding: 12px 0;
        text-align: center;
        margin-bottom: 10px;
        border-radius: 10px;
        .name {
          font-size: 14px;
        }
        .num {
          font-size: 24px;
          margin-top: 4px;
        }
      }
    }
    .apilist-content {
      padding: 6px 0;
      width: 100%;
      text-align: center;
      margin-top: 10px;
      .api-title {
        padding: 10px 0;
        border-radius: 2px;
        background-color: #f2f7ff;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 12px;
        color: #666666;
      }
      .apilist-box {
        max-height: 756px;
        // height: 756px;
        overflow-y: auto;
      }
      .apilist {
        margin-top: 4px;
        padding: 8px 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 12px;
        color: #333333;
        .lowColor {
          color: #67c23a;
        }
      }
      .apiColor {
        background-color: #f6faff;
      }
    }
  }
}
</style>
